--SpyVehicle by DreSam911
--Source is not open for use/distribution.

local SpyVehicle = {}

function SpyVehicle.unload()
end
function SpyVehicle.init()
end

function SpyVehicle.tick()
	local player = PLAYER.PLAYER_ID()
	local playerPed = PLAYER.PLAYER_PED_ID()
	local bPlayerExists = ENTITY.DOES_ENTITY_EXIST(playerPed)
	local lastVeh = PLAYER.GET_PLAYERS_LAST_VEHICLE()
	local currentVeh = PED.GET_VEHICLE_PED_IS_USING(playerPed)
	if ((bPlayerExists) and (lastVeh ~= currentVeh) and ((PLAYER.GET_PLAYER_WANTED_LEVEL(player) > 0) or (PLAYER.GET_PLAYER_WANTED_LEVEL(player) == 0))) then
		WEAPON.GIVE_DELAYED_WEAPON_TO_PED(playerPed, GAMEPLAY.GET_HASH_KEY("WEAPON_DIGISCANNER"), 1000, true)
		wait(10000)
		AI.TASK_TURN_PED_TO_FACE_ENTITY(playerPed, lastVeh, 1000)
		AI.TASK_AIM_GUN_AT_ENTITY(playerPed, lastVeh, -1, true)
		VEHICLE.SET_VEHICLE_DOORS_SHUT(lastVeh, true)
		VEHICLE.SMASH_VEHICLE_WINDOW(lastVeh, 0)
		VEHICLE.SMASH_VEHICLE_WINDOW(lastVeh, 1)
		VEHICLE.SMASH_VEHICLE_WINDOW(lastVeh, 2)
		VEHICLE.SMASH_VEHICLE_WINDOW(lastVeh, 3)
		wait(3000)
		VEHICLE.SET_VEHICLE_TYRES_CAN_BURST(lastVeh, true)
		VEHICLE.SET_VEHICLE_TYRE_BURST(lastVeh, 0, true, 1000.0)
		VEHICLE.SET_VEHICLE_TYRE_BURST(lastVeh, 1, true, 1000.0)
		VEHICLE.SET_VEHICLE_TYRE_BURST(lastVeh, 2, true, 1000.0)
		VEHICLE.SET_VEHICLE_TYRE_BURST(lastVeh, 3, true, 1000.0)
		VEHICLE.SET_VEHICLE_TYRE_BURST(lastVeh, 4, true, 1000.0)
		VEHICLE.SET_VEHICLE_TYRE_BURST(lastVeh, 5, true, 1000.0)
		VEHICLE.SET_VEHICLE_TYRE_BURST(lastVeh, 6, true, 1000.0)
		VEHICLE.SET_VEHICLE_TYRE_BURST(lastVeh, 7, true, 1000.0)
		wait(3000)
		VEHICLE.SET_VEHICLE_ENGINE_HEALTH(lastVeh, -4000)
		wait(2000)
		VEHICLE.EXPLODE_VEHICLE(lastVeh, false, true)
		AI.CLEAR_PED_TASKS(playerPed)
		WEAPON.REMOVE_WEAPON_FROM_PED(playerPed, GAMEPLAY.GET_HASH_KEY("WEAPON_DIGISCANNER"))
		PED.RESET_PED_LAST_VEHICLE(playerPed)	
	end
end


return SpyVehicle